Application class is the base class for Kanzi applications. More...
#include <kanzi/core.ui/application/application.hpp>
Public Member Functions | |
Application () | |
Constructs the application object. | |
Vector2 | getRenderingAreaOffset () const |
Returns the translation that Kanzi uses as the arrange transformation of the default Screen node. | |
TextureSharedPtr | getRootCompositionTarget () const |
Returns the root composition target of the application. | |
StartupProfilerRegistry & | getStartupProfilerRegistry () const |
Gets the startup profiler registry. | |
void | initialize (const SystemProperties &systemProperties) |
Initializes the application to a consistent state. | |
void | initializeGL () |
Initializes the graphics language subsystem. | |
bool | loadKzbFile (string_view fileName, bool setStartupPrefab) |
Loads a kzb file or multiple kzb files listed in a configuration file. | |
void | main (const SystemProperties &systemProperties) |
Application entry point. | |
void | resumeGL () |
Resumes the graphics language subsystem. | |
void | setRenderingAreaOffset (Vector2 offset) |
Sets the translation that Kanzi uses as the arrange transformation of the default Screen node. | |
void | setRootCompositionTarget (TextureSharedPtr compositionTarget) |
Sets the root composition target of the application. | |
void | suspendGL () |
Suspends the graphics language subsystem. | |
void | uninitialize () |
Uninitializes the application. | |
void | uninitializeGL () |
Uninitializes the graphics language subsystem. | |
~Application () override | |
Destructs the application object. | |
State modifiers. | |
void | pause () |
Puts the application from the Running state to the Paused state. | |
void | resume () |
Resumes the application from the Paused state to the Running state. | |
void | quit () |
Quits the application. | |
Studio preview specific functions. | |
void | patchProject (uintmax_t byteCount, const byte *bytes) |
Applies a Kanzi Studio Preview patch. | |
Public Member Functions inherited from kanzi::Module | |
virtual void | destroy () |
virtual MetaclassContainer | getMetaclassesOverride () |
Module () | |
virtual void | registerDebugRenderingFunctions (DebugRenderRegistry &) |
Registers the debug rendering functions of the module. | |
virtual void | registerMetadataOverride (ObjectFactory &) |
Registers the rest of the module metadata, such as loaders for types in the module. | |
void | setDomain (Domain *domain) |
Sets the domain. | |
Protected Member Functions | |
Initialization functions. | |
virtual void | initializeProperties (const SystemProperties &systemProperties) |
Loads the application properties, based on configuration file and command-line arguments. | |
virtual void | initializeSystem () |
Initializes profiling, event sources, and graphics output. | |
virtual void | initializePlatform () |
Initializes platform configuration. | |
virtual void | uninitializePlatform () |
Unitializes platform configuration. | |
virtual void | initializeDomain () |
Initializes Kanzi Domain and loads a kzb file. | |
virtual void | initializeMainLoopTasks () |
Attaches the default tasks to the main loop scheduler. | |
void | applyMainLoopConfigs () |
Applies the frame limit and idle-suspension configurations from the application properties to the main loop scheduler, and attaches event handles and preconditions. | |
void | setFontBackendProperties () |
Applies the font backend properties from the application properties to the FontManager. | |
Input stage functions. | |
void | clearEventQueue () |
Clears the event queue. | |
void | gatherEvents () |
Gathers all input events from the event sources into the event queue. | |
void | handleApplicationEvents () |
Executes the application-defined event handler on all events in the event queue. | |
virtual void | handleEvents (EventQueue &eventQueue) |
Executes the application-defined event handler on all events in the event queue. | |
void | handleGraphicsEvents () |
Executes the event handler of the graphics subsystem. The events to handle are from the event queue. | |
void | handleInputManagerEvents () |
Executes the event handler of the input subsystem. The events to handle are from the event queue. | |
User stage functions. | |
void | loadStartupKzb () |
Instantiates and attaches the startup Screen node from the startup prefab. | |
void | progressDeploymentQueue () |
Processes the deployment queue for asynchronous loading tasks. | |
void | updateRenderer (chrono::nanoseconds deltaTime) |
Advances renderer clock with time delta, and attaches active graphics output to it. | |
void | measurePerformance (chrono::nanoseconds deltaTime) |
Updates the calculation of the Application frame rate. | |
Layout stage functions. | |
void | adjustRenderingArea () |
Sets the rendering area on the graphics output based on the size, orientation, and metrics. | |
void | layout () |
Lays out the node tree. | |
Animate stage functions. | |
void | tickAnimations (chrono::nanoseconds deltaTime) |
Ticks all the active animations. | |
Render stage functions. | |
virtual void | render () |
Renders the node tree. | |
void | renderPerformanceInfo () |
Renders the Performance HUD. | |
void | clearAllRenderBuffers (ColorRGBA clearColor) |
Clears all render buffers. | |
Present stage functions. | |
void | present () |
Updates the graphics output buffer with the rendered node tree. | |
Callbacks. | |
virtual void | onStartup () |
Callback for the startup logic. | |
virtual void | onShutdown () |
Callback for the shutdown logic. | |
virtual void | onConfigure (ApplicationProperties &configuration) |
Callback for configuring the application properties. | |
virtual void | onProjectLoaded () |
Callback for initializations that use data from a kzb file. | |
virtual void | onUpdate (chrono::nanoseconds deltaTime) |
Callback for the update logic. | |
virtual void | onPointerInputEvent (const PointerEvent &pointerEvent) |
Callback for handling of input events from a pointing device, such as a mouse or touch screen. | |
virtual void | onKeyInputEvent (const KeyEvent &keyEvent) |
Callback for handling input events from keyboard. | |
virtual optional< chrono::nanoseconds > | onSuspend (chrono::nanoseconds remainingFrameAllotment) |
Callback for determining the duration of suspension in a main loop frame. | |
virtual void | onPause () |
Kanzi calls this callback when the application main loop enters the Paused state. | |
virtual void | onResume () |
Kanzi calls this callback when the application main loop returns from the Paused to the Running state. | |
virtual void | onResumeCheck () |
Kanzi calls this callback for the event handling logic when the application main loop is in the Paused state. | |
Overrides. | |
virtual void | mainOverride (const SystemProperties &systemProperties) |
Override function for main(). | |
virtual void | initializeOverride (const SystemProperties &systemProperties) |
Override function for initialize(). | |
virtual void | uninitializeOverride () |
Override function for uninitialize(). | |
virtual void | initializeGLOverride () |
Override function for initializeGL(). | |
virtual void | uninitializeGLOverride () |
Override function for uninitializeGL(). | |
virtual void | suspendGLOverride () |
Override function for suspendGL(). | |
virtual void | resumeGLOverride () |
Override function for resumeGL(). | |
virtual void | progressDeploymentQueueOverride () |
Override function for progressDeploymentQueue(). | |
virtual void | setScreenOverride () |
Override function for setScreen(). | |
Target preview specific functions. | |
virtual void | installInitialPatchHandler () |
Installs initial patch handler. | |
Protected Member Functions inherited from kanzi::Module | |
virtual | ~Module ()=default |
Destructor. | |
Protected Attributes | |
ApplicationProperties | m_applicationProperties |
Application properties. | |
KzuEngine * | m_engine |
Kanzi Engine instance. | |
MainLoopTaskToken | m_loadStartupKzbToken |
The token of LoadStartyKzb Main Loop Scheduler task. | |
MainLoopScheduler | m_mainLoopScheduler |
Main loop scheduler. | |
unique_ptr< PerformanceInfo > | m_performanceInfo |
Performance HUD information. | |
bool | m_projectLoaded |
Flag to be set when project has been loaded. | |
string | m_startupPrefabUrl |
URL of the startup prefab. | |
SystemProperties | m_systemProperties |
Container of command line parameters of the program. | |
Protected Attributes inherited from kanzi::Module | |
Domain * | m_domain |
The domain this module is registered to. | |
Friends | |
class | AppfwInitialPatchHandler |
class | PreviewApplication |
Accessors and mutators. | |
Domain * | getDomain () const |
Access domain. | |
Renderer3D * | getRenderer3D () const |
Access the renderer. | |
Node2DSharedPtr | getRoot () const |
Access the root node. | |
ScreenSharedPtr | getScreen () const |
Access the Screen node. | |
void | setScreen (ScreenSharedPtr screen) |
Sets, configures, and attaches the Screen node of the Application. | |
const MainLoopScheduler & | getMainLoopScheduler () const |
Access the associated MainLoopScheduler. | |
MainLoopScheduler & | getMainLoopScheduler () |
Access the associated MainLoopScheduler. | |
ResourceManager * | getResourceManager () const |
Access resource manager. | |
KZ_DEPRECATED InputManager * | getInputManager () const |
Access input manager. | |
detail::MessageDispatcher * | getMessageDispatcher () const |
Access message dispatcher. | |
float | getFramesPerSecond () const |
Gets the frame rate of the application. | |
size_t | getGraphicsOutputCount () const |
Access graphics output count. | |
GraphicsOutputSharedPtr | getGraphicsOutput (size_t index=0) const |
Access graphics outputs. | |
template<typename Interface > | |
shared_ptr< Interface > | getGraphicsOutput (size_t index) const |
Query graphics output interfaces. | |
void | appendGraphicsOutput (GraphicsOutputSharedPtr graphicsOutput) |
Attach graphics output. | |
void | removeGraphicsOutput (size_t index=0) |
Remove graphics output. | |
size_t | getEventSourceCount () const |
Access event source count. | |
EventSourceSharedPtr | getEventSource (size_t index=0) const |
Access event sources. | |
void | appendEventSource (EventSourceSharedPtr eventSource) |
Attach event source to domain and register its event handle with main loop scheduler. | |
void | removeEventSource (size_t index=0) |
Remove event source. | |
MainLoopState | getState () const |
Access application state. | |
ApplicationProperties | getApplicationProperties () const |
Access application properties. | |
ApplicationProperties::PerformanceInfoLevel | getPerformanceInfoLevel () const |
Gets the Performance HUD information level. | |
void | setPerformanceInfoLevel (ApplicationProperties::PerformanceInfoLevel level) |
Sets the Performance HUD information level. | |
void | loadFontEngine (ApplicationProperties::FontEngine fontEngine) |
Loads the font engine for the font manager. | |
void | setAllowIndefiniteSleep (bool enabled) |
Sets or resets the flag that allows indefinite sleep. | |
void | setDeploymentQueueTimeBudget (chrono::nanoseconds budget) |
Sets the time budget used to deploy asynchronously loaded Resources per frame. | |
void | logStartupProfilingData () const |
Logs startup profiling data. | |
virtual bool | isToolPresent () const |
Indicates whether application is running in the Kanzi Studio Preview. | |
void | logGraphicsInformation () |
Log graphics information based on application properties. | |
KZ_DEPRECATED KzuEngine * | getEngine () const |
Access Kanzi Engine. | |
PerformanceInfo & | acquirePerformanceInfo () |
Acquire performance information object. | |
void | restoreNodeResources (Screen &screen) |
Restores node resources after application sleep by calling Node::restoreResources() recursively for the nodes in the tree. | |
Additional Inherited Members | |
Public Types inherited from kanzi::Module | |
typedef vector< const Metaclass * > | MetaclassContainer |
typedef MetaclassContainer::iterator | MetaclassIterator |
Application class is the base class for Kanzi applications.
It implements the Kanzi main loop with help of MainLoopScheduler.
You can customize your application by overriding the virtual functions of the Application class.
You can also customize the main loop using the MainLoopScheduler, which you can access with getMainLoopScheduler(). The MainLoopScheduler lets you add or modify the tasks and stages of the main loop. Kanzi adds the default main loop tasks to the respective stages inside initializeMainLoopTasks().
This diagram shows the overall application control flow. Green items are virtual functions. Gray items are main loop stages. Dotted items are main loop callbacks.
|
explicit |
Constructs the application object.
|
override |
Destructs the application object.
void kanzi::Application::initialize | ( | const SystemProperties & | systemProperties | ) |
Initializes the application to a consistent state.
After constructing the application, this is the first function that the application framework calls. This function tries to read the file application.cfg. Do not call this function before the file system of the operating system has been initialized.
To change the default behavior, override initializeOverride().
systemProperties | Command line parameters of the program. |
void kanzi::Application::initializeGL | ( | ) |
Initializes the graphics language subsystem.
The application framework calls this function before entering the program main loop, but after the application framework activates a GL context. It initializes OpenGL-related subsystems.
To change the default behavior, override initializeGLOverride().
void kanzi::Application::resumeGL | ( | ) |
Resumes the graphics language subsystem.
If you call suspendGL() during suspension, the application framework calls this function during application resume. This function deploys GPU resources that were undeployed during suspendGL().
To change the default behavior, override resumeGLOverride().
void kanzi::Application::main | ( | const SystemProperties & | systemProperties | ) |
Application entry point.
This high-level function implements the default initialization and the main loop. The application framework calls this function, except on callbacks-only systems.
To change the default behavior, override mainOverride().
systemProperties | Command line parameters of the program. |
void kanzi::Application::uninitialize | ( | ) |
Uninitializes the application.
This is the last function that the application framework calls before destruction.
To change the default behavior, override uninitializeOverride().
void kanzi::Application::uninitializeGL | ( | ) |
Uninitializes the graphics language subsystem.
The application framework calls this function after exiting the program main loop, but before it deactivates a GL context. It undeploys all GPU resources.
To change the default behavior, override uninitializeGLOverride().
void kanzi::Application::suspendGL | ( | ) |
Suspends the graphics language subsystem.
The application framework calls this function during application suspension, on systems where the graphics language resources are not guaranteed to be retained until the application resumes. It undeploys all GPU resources and reschedules them for redeployment.
When your applications suspends, the GPU resources not stored in a kzb file become invalid. Destroy these resources and recreate them on resume. Make sure that after recreating a resource the pointers are correct. Kanzi automatically restores all other resources.
To change the default behavior, override suspendGLOverride().
void kanzi::Application::pause | ( | ) |
Puts the application from the Running state to the Paused state.
void kanzi::Application::resume | ( | ) |
Resumes the application from the Paused state to the Running state.
void kanzi::Application::quit | ( | ) |
Quits the application.
Domain * kanzi::Application::getDomain | ( | ) | const |
Access domain.
Renderer3D * kanzi::Application::getRenderer3D | ( | ) | const |
Access the renderer.
Node2DSharedPtr kanzi::Application::getRoot | ( | ) | const |
Access the root node.
ScreenSharedPtr kanzi::Application::getScreen | ( | ) | const |
void kanzi::Application::setScreen | ( | ScreenSharedPtr | screen | ) |
Sets, configures, and attaches the Screen node of the Application.
The default implementation associates the screen of the application with InputManager and FocusManager instances. You can configure the given screen in setScreenOverride().
If the Application already has a Screen node set, Kanzi detaches and releases that Screen, and sets the given screen node.
Kanzi calls this method automatically on loadStartupKzb().
screen | Shared pointer to the Screen node to set. |
const MainLoopScheduler & kanzi::Application::getMainLoopScheduler | ( | ) | const |
Access the associated MainLoopScheduler.
MainLoopScheduler & kanzi::Application::getMainLoopScheduler | ( | ) |
Access the associated MainLoopScheduler.
ResourceManager * kanzi::Application::getResourceManager | ( | ) | const |
Access resource manager.
KZ_DEPRECATED InputManager * kanzi::Application::getInputManager | ( | ) | const |
Access input manager.
detail::MessageDispatcher * kanzi::Application::getMessageDispatcher | ( | ) | const |
Access message dispatcher.
float kanzi::Application::getFramesPerSecond | ( | ) | const |
Gets the frame rate of the application.
To make sure that this function returns the correct frame rate, the main loop scheduler task MeasurePerformance calls measurePerformance() once per frame by default.
If you override the user stage tasks of the main loop scheduler, including the MeasurePerformance task, call measurePerformance() manually every frame. This way you make sure that getFramesPerSecond() returns valid values.
size_t kanzi::Application::getGraphicsOutputCount | ( | ) | const |
Access graphics output count.
GraphicsOutputSharedPtr kanzi::Application::getGraphicsOutput | ( | size_t | index = 0 | ) | const |
Access graphics outputs.
index | Index of the graphics output to access. |
|
inline |
Query graphics output interfaces.
Interface | Interface of the graphics output to query. |
index | Index of the graphics output to query. |
void kanzi::Application::appendGraphicsOutput | ( | GraphicsOutputSharedPtr | graphicsOutput | ) |
Attach graphics output.
graphicsOutput | Shared pointer to the graphics output to attach. |
void kanzi::Application::removeGraphicsOutput | ( | size_t | index = 0 | ) |
Remove graphics output.
index | Index of the graphics output to remove. |
size_t kanzi::Application::getEventSourceCount | ( | ) | const |
Access event source count.
EventSourceSharedPtr kanzi::Application::getEventSource | ( | size_t | index = 0 | ) | const |
Access event sources.
index | Index of the event source to access. |
void kanzi::Application::appendEventSource | ( | EventSourceSharedPtr | eventSource | ) |
Attach event source to domain and register its event handle with main loop scheduler.
To attach event source to domain without registering event handle, use Domain::appendEventSource(). To register event handle with main loop scheduler without attaching to domain, use MainLoopScheduler::setInputEventHandle().
eventSource | Shared pointer to the event source to attach. |
void kanzi::Application::removeEventSource | ( | size_t | index = 0 | ) |
Remove event source.
index | Index of the event source to remove. |
MainLoopState kanzi::Application::getState | ( | ) | const |
Access application state.
ApplicationProperties kanzi::Application::getApplicationProperties | ( | ) | const |
Access application properties.
|
inline |
Gets the Performance HUD information level.
If the Performance HUD information level is not ApplicationProperties::PerformanceInfoLevelDisabled, Kanzi draws the Performance HUD after calling onPostRender().
|
inline |
Sets the Performance HUD information level.
This is equal to the application configuration ApplicationProperties::PerformanceInfoLevel option.
level | - To turn off the Performance HUD, use ApplicationProperties::PerformanceInfoLevelDisabled (0). The default value.
|
void kanzi::Application::loadFontEngine | ( | ApplicationProperties::FontEngine | fontEngine | ) |
Loads the font engine for the font manager.
fontEngine | The font engine that the font manager uses. |
Sets or resets the flag that allows indefinite sleep.
enabled | - To enable indefinite sleep, set to true.
|
|
inline |
Sets the time budget used to deploy asynchronously loaded Resources per frame.
This does not guarantee that the work will be completed within the budget, just that no new items will be started after the budget has expired. At a minimum, one item will be processed each frame if it exists.
budget | Amount of time to spend processing Deployment Queue items per frame. |
Applies a Kanzi Studio Preview patch.
Kanzi Studio Preview uses this function internally.
byteCount | Size of kzb file. |
bytes | Pointer to the contents of the kzb file. |
|
inline |
Gets the startup profiler registry.
Loads a kzb file or multiple kzb files listed in a configuration file.
fileName | Name of the kzb file to load or the name of the configuration file from which to read the names of kzb files to load. |
setStartupPrefab | Whether to set the startup prefab of the loaded kzb file as the startup prefab of the application. When loading multiple kzb files, Kanzi uses the startup prefab from the kzb file it loads last. |
Vector2 kanzi::Application::getRenderingAreaOffset | ( | ) | const |
void kanzi::Application::setRootCompositionTarget | ( | TextureSharedPtr | compositionTarget | ) |
Sets the root composition target of the application.
compositionTarget | The composition target texture to use. |
TextureSharedPtr kanzi::Application::getRootCompositionTarget | ( | ) | const |
Returns the root composition target of the application.
|
protectedvirtual |
Loads the application properties, based on configuration file and command-line arguments.
systemProperties | Command line parameters of the program. |
Initializes profiling, event sources, and graphics output.
Initializes platform configuration.
Unitializes platform configuration.
Initializes Kanzi Domain and loads a kzb file.
Attaches the default tasks to the main loop scheduler.
|
protected |
Applies the frame limit and idle-suspension configurations from the application properties to the main loop scheduler, and attaches event handles and preconditions.
|
protected |
Applies the font backend properties from the application properties to the FontManager.
|
protected |
Clears the event queue.
|
protected |
Gathers all input events from the event sources into the event queue.
|
protected |
Executes the application-defined event handler on all events in the event queue.
|
protectedvirtual |
Executes the application-defined event handler on all events in the event queue.
eventQueue | Reference to the event queue for user input and window events. |
|
protected |
Executes the event handler of the graphics subsystem. The events to handle are from the event queue.
|
protected |
Executes the event handler of the input subsystem. The events to handle are from the event queue.
|
protected |
|
protected |
Processes the deployment queue for asynchronous loading tasks.
By default this function processes every frame a single item from the deployment queue of background loading tasks.
To change the default behavior, override progressDeploymentQueueOverride().
|
protected |
Advances renderer clock with time delta, and attaches active graphics output to it.
deltaTime | Time in nanoseconds elapsed since the previous frame. |
|
protected |
Updates the calculation of the Application frame rate.
To calculate the frame rate correctly, Kanzi must call this function once per frame. The default main loop scheduler task MeasurePerformance does this.
deltaTime | Time in nanoseconds elapsed between the start of the previous frame and the start of the current frame. |
|
protected |
Sets the rendering area on the graphics output based on the size, orientation, and metrics.
|
protected |
Lays out the node tree.
|
protected |
Ticks all the active animations.
deltaTime | Time in nanoseconds since the previous frame. |
|
protected |
Renders the Performance HUD.
Clears all render buffers.
|
protected |
Updates the graphics output buffer with the rendered node tree.
Callback for the startup logic.
Kanzi calls this function immediately after the application initialization.
Callback for the shutdown logic.
Kanzi calls this function immediately before the application un-initialization.
|
protectedvirtual |
Callback for configuring the application properties.
Kanzi calls this callback before it reads the application.cfg and before it initializes the graphics subsystem.
configuration | Allows modification of the application properties. |
Reimplemented in kanzi::ExampleApplication.
Callback for initializations that use data from a kzb file.
Kanzi calls this function right after it loads a kzb file.
Callback for the update logic.
Kanzi calls this function every frame in the User stage of the main loop.
deltaTime | Time in nanoseconds elapsed since the previous frame. |
|
protectedvirtual |
Callback for handling of input events from a pointing device, such as a mouse or touch screen.
Kanzi calls this function inside the Input stage of the main loop.
pointerEvent | Reference to the event. |
Callback for handling input events from keyboard.
Kanzi calls this function inside the Input stage of the main loop.
keyEvent | Reference to the event. |
Reimplemented in kanzi::ExampleApplication.
|
protectedvirtual |
Callback for determining the duration of suspension in a main loop frame.
Kanzi calls this function when the main loop decides to enter suspension.
remainingFrameAllotment | Time remaining in the current frame based on the configured frame limit and time elapsed since its start. |
Kanzi calls this callback when the application main loop enters the Paused state.
Kanzi calls this callback when the application main loop returns from the Paused to the Running state.
Kanzi calls this callback for the event handling logic when the application main loop is in the Paused state.
|
protectedvirtual |
|
protectedvirtual |
Override function for initialize().
systemProperties | Command line parameters of the program. |
Override function for uninitialize().
Override function for initializeGL().
Override function for uninitializeGL().
Override function for suspendGL().
Override function for resumeGL().
Override function for progressDeploymentQueue().
Override function for setScreen().
The default implementation associates the screen of the application with InputManager and FocusManager instances. To disable input and focus management on the application screen, override this method to clear the input and focus managers from the application screen.
|
protected |
Logs startup profiling data.
Indicates whether application is running in the Kanzi Studio Preview.
|
protected |
Log graphics information based on application properties.
|
protected |
Access Kanzi Engine.
|
protected |
Acquire performance information object.
If performance information object does not exist, this function creates it.
Restores node resources after application sleep by calling Node::restoreResources() recursively for the nodes in the tree.
screen | The Screen of the node tree for which to restore resources. |
Installs initial patch handler.
Kanzi calls this function internally, when the application loads the target preview plugin. When called, this function sets a PatchingNotificationHandler to the domain to listen for the initial patch and modify the existing node tree of the application so that the patches are applicable.
|
protected |
Container of command line parameters of the program.
|
protected |
Application properties.
|
mutableprotected |
Kanzi Engine instance.
|
protected |
Performance HUD information.
|
protected |
Flag to be set when project has been loaded.
|
protected |
Main loop scheduler.
|
protected |
The token of LoadStartyKzb Main Loop Scheduler task.
|
protected |
URL of the startup prefab.